package org.example.translate_braille.controller;


import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.example.translate_braille.entity.Photo;
import org.example.translate_braille.resdata.X;
import org.example.translate_braille.service.PhotoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import springfox.documentation.annotations.ApiIgnore;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Jacky
 * @since
 */
@RestController
@RequestMapping("/translate_braille/photo")
public class PhotoController {
    @Autowired
    PhotoService photoService;


    @GetMapping("/photoTest")
    public String photoTest(){
        return "hello world";
    }


    @PostMapping("/inOrUpPhoto")
    public X<Photo> inOrUpPhoto(@RequestBody JSONObject pic){
        //收到的json格式内有者图片的各种信息
        String openId = pic.getString("openid");
        String picBase64 = pic.getString("picture");
        String fileName = pic.getString("picName");
        String picType = pic.getString("picType");
        Photo photo = new Photo();
        photo.setUserId(openId);
        photo.setPhotoName(fileName);
        //调用底层的Service的实现方法
        return photoService.inOrUpPhoto(photo,picBase64,picType);
    }

    @PostMapping("/showPhotoList")
    public X<Photo> showPhotoList(@RequestBody JSONObject jsonObject){
        String openId = jsonObject.getString("openid");
        return photoService.showPhotoList(openId);
    }

    @PostMapping("/deletePhoto")
    @ApiOperation(value="删除+批量删除")
    public X<Photo> deletePhoto(@RequestBody JSONObject pic){
        String openId = pic.getString("openid");
        String fileName = pic.getString("picName");
        Photo photo = new Photo();
        photo.setPhotoName(fileName);
        photo.setUserId(openId);
        return photoService.deletePhoto(photo);
    }

}

